package com.huluobo.a2303mdmdemo.demo

import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue

/**
 *  Created by LC on 2025/8/16.
 */

@Composable
fun MyDialog() {

    //一般弹窗都需要用一个bool类型来标记,来控制是否显示弹窗
    var isShow by remember {
        mutableStateOf(false)
    }

    Column {
        Button(onClick = {
            isShow = true
        }) {
            Text(text = "弹窗")
        }
    }

    if (isShow) {
        AlertDialog(
            //点击外部情况
            onDismissRequest = {
                //可以通过点击弹窗的外部来控制是否是一个强制弹窗
                isShow = false
            },
            //确认按钮
            confirmButton = {
                Column {
                    TextButton(onClick = {
                        isShow = false
                    }) {
                        Text(text = "确认")
                    }
                }
            },
            //取消按钮
            dismissButton = {
                TextButton(onClick = {
                    isShow = false
                }) {
                    Icon(imageVector = Icons.Default.Close, contentDescription = "")
                }
            },
            //弹窗标题
            title = {
                Text(text = "这是弹窗的标题")
            },
            //弹窗图标
            icon = {
                Icon(imageVector = Icons.Default.Favorite, contentDescription = "")
            },
            //弹窗文本
            text = {
                Text(text = "这是弹窗的文本")
            }
        )
    }

}